﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BikeManageBusiness.logical;
using Data.Common;
using Data.Enum;
using DataAccess.BikeManage.logical;

namespace BikeManageWeb
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Button1_Click(object sender, EventArgs e)
        {


            byte y1 = 2;
            byte ylast = 13;
            byte month = 1;
            byte day = 1;
            byte hour = 1;
            byte min = 1;
            byte second = 1;


            UInt32 i32max = UInt32.MaxValue;
            UInt32 i32min = UInt32.MinValue;

            UInt32 i32 = 256;
            byte[] i32s = BitConverter.GetBytes(i32);
            i32 = BitConverter.ToUInt32(i32s, 0);

            double m = 1992.22;
            DateTime d = DateTime.Now;
            byte[] ms = BitConverter.GetBytes(m);
            double mm = BitConverter.ToDouble(ms, 0);
            //byte[] ds = Zq58Logical.DateToByte(d);
            //DateTime dd = Zq58Logical.ByteToDate(ds);

            double money = 1991.1;
            byte[] rData = new byte[28];//返回数据
            byte[] amount = new byte[4];//充值金额
            amount = Encoding.ASCII.GetBytes(money.ToString());
            byte[] datetime = new byte[7];//交易时间
            datetime = Encoding.Unicode.GetBytes(DateTime.Now.ToString());
            byte[] xx = Encoding.ASCII.GetBytes("你好你好你好");
            string xxx = Encoding.ASCII.GetString(xx);

            CpuAccount a = new CpuAccount() { DisplayName = "你好好你好你" };
            Zq58Logical zq58Logical = new Zq58Logical();
            byte[] x = zq58Logical.TransAccount(a, 192);

            byte[] data = new byte[192];
            byte fileAdd = 0x00;
            byte fileLen = 0x02;
            int status = Zq58Logical.ZQ58_Read0009(1, 1, fileAdd, fileLen, ref data[0]);
        }

        protected void Button2_Click(object sender, EventArgs e)
        {
            //jsh_account account=new jsh_account(){addr1 = "长沙市芙蓉区110号",cpuno = "17872387234jj",sex = "男",zjtype = "身份证",zjhm = "430723199901101232",fzjg = "长沙公安局",displayname = "向钊豫",mobile = "13467555726",cpuid = "123123sssd1243",cardtype = "01",feeid = 1};
            //Zq58LogicalXX logical = new Zq58LogicalXX();
            //logical.WriteAccountInfo(account);

            CpuAccount a = new CpuAccount() { CpuCardNo = "xxxda132323",  CpuCardStatus = "正常", CpuCardType = "消费卡",  CpuCardVersion = "v1.0", DisplayName = "向钊豫", Fee = "1.3",  IdCardNo = "37784889923", IdCardType = "身份证", Mobile = "12883771", Nation = "中国", Phone = "322323", Sex = "男" };
            Zq58Logical log = new Zq58Logical();
            log.WriteAccountInfo(a);
        }

        protected void Button3_Click(object sender, EventArgs e)
        {
            //Zq58LogicalXX logical = new Zq58LogicalXX();
            //logical.ReadAccountInfo();
            Zq58Logical lo = new Zq58Logical();
            lo.ReadAccountInfo();
        }

        protected void Button4_Click(object sender, EventArgs e)
        {
            Zq58Logical logical = new Zq58Logical();
            logical.PurseSave(23112);
        }

        protected void Button5_Click(object sender, EventArgs e)
        {
            Zq58Logical logical = new Zq58Logical();
            logical.QueryPurse();
        }

        protected void Button6_Click(object sender, EventArgs e)
        {
            Dkqa16dLogical logical = new Dkqa16dLogical();
            //logical.GetIdCardData(1001);//1-16com 1001-1006usb
            //for (int i = 1001; i < 1007; i++)
            //{
            //    logical.GetIdCardData(i);
            //}
            logical.GetIdCardData();
        }

        protected void Button7_Click(object sender, EventArgs e)
        {
            //string s = Convert.ToString(1232232222, 16).PadLeft(8, '0');//BitConverter.GetBytes(12322);

            //string ass = string.Format("2222222222").PadLeft(8, '0');

            //Int32 s1 = Convert.ToInt32(s, 16);

            //DbLogical dbLogical = new DbLogical();

            //dbLogical.GetBusiness(1, 2, new DateTime(2013, 12, 06), new DateTime(2013, 12, 7, 23, 59, 59));

            //dbLogical.RechargeYourPurse(3489.78m, 100, "B3719806","xx",1,"xx",1);


            //dbLogical.GetLockPiles(1, 20, "da", "dafd", 1, 1, "dlakjdf");

            //dbLogical.GetConsumes(1, 20, "111", "38883", "xiangzy", "123123");

            //Int32 bi = 1;
            //byte[] bis = BitConverter.GetBytes(bi);

            //byte[] biss = { 0x00, 0x00, 0x00, 0x01 };

            //DbLogical dbLogical=new DbLogical();

            //dbLogical.GetConsumes(1, 20, null, null, null, "11111");

            //dbLogical.OpenAccount(new jsh_account(){username = "xiangzy"}, 0, 10, 10);

            //dbLogical.OpenAccount(new jsh_account() { zzhm = "111" }, 0, 10, 10);

            //dbLogical.OpenAccount(new jsh_account() { cpuid = "000" }, 0, 10, 10);

            //dbLogical.GetAccounts(1, 20, "xiangzy", null, null);

            //dbLogical.GetAccounts(1, 20, null, "111", null);
            //dbLogical.GetAccounts(1, 20, "xiangzy", null, "000");

            

            Zq58Logical zq58Logical = new Zq58Logical();

            decimal d1 = zq58Logical.GetOutMoney(12883, 100);
            int d2 = zq58Logical.PutInMoney(d1, 100);

            //zq58Logical.WriteAccountInfo(new CpuAccount(){Address = "长沙",CpuCardId = "111",CpuCardNo = "ddd",CpuCardStatus = "正常",CpuCardType = "消费",CpuCardVersion = "v1.0",DisplayName = "向钊豫",Fee = "100",IdCardNo = "33333333",IdCardType = "身份证",Mobile = "111111",Nation ="中国",Phone = "ssss",Sex = "男"});
            //ResultInfo<CpuAccount> aa = zq58Logical.ReadAccountInfo();

            BorrowBike bb = new BorrowBike() { OpenAccountDate = "20131010", EndAccountDate = "20201010", BorrowCpuid = "B3719806", BorrowTime = "20131118202020" };
            zq58Logical.WriteBorrowBikeInfo(bb);
            ResultInfo<BorrowBike> b1 = zq58Logical.ReadBorrowBikeInfo();

            byte[] time = zq58Logical.DateTimeToBytes("22171116113950");
            zq58Logical.BytesToDateTime(time);

            //zq58Logical.QueryPurse();
            string str = "00046B42";
            byte[] result = zq58Logical.MoneyToBytes(289602,4);

            byte[] ms = zq58Logical.MoneyToBytes(12321,4);
            int sm = zq58Logical.BytesToMoney(ms);

            byte[] ms1 = zq58Logical.MoneyToBytes(1000000000,4);
            int sm1 = zq58Logical.BytesToMoney(ms1);

            byte[] ms2 = zq58Logical.MoneyToBytes(10,4);
            int sm2 = zq58Logical.BytesToMoney(ms2);

            byte[] bys = zq58Logical.DateTimeToBytes("201107010");
            string syb = zq58Logical.BytesToDateTime(bys);

            byte[] bys1 = zq58Logical.DateTimeToBytes("20131115193320");
            string syb1 = zq58Logical.BytesToDateTime(bys1);

            byte[] pinvalue = new byte[6];
            pinvalue = zq58Logical.GetAsciiBytes("321136", 6);

            byte x = Convert.ToByte("3");

            zq58Logical.GetZ58SWErrorInfo(0x62, 0x81);
            zq58Logical.GetZ58SWErrorInfo(98, 129);

            CpuAccount account = new CpuAccount() { CpuCardNo = "xxnige12311,xlll",  CpuCardStatus = "正常", CpuCardType = "消费卡",  CpuCardVersion = "v1.0", DisplayName = "向钊豫", Fee = "1.5", Address = "澧县籍贯", IdCardNo = "11xx11niffa", IdCardType = "身份证", Mobile = "13467555726", Nation = "常德", Phone = "32121123", Sex = "男" };
            byte[] filedata = new byte[192];
            filedata = zq58Logical.TransAccount(account, 192);
            CpuAccount a = new CpuAccount();
            a = zq58Logical.ReTransAccount(filedata);
        }

        protected void Button8_Click(object sender, EventArgs e)
        {
            int num = Convert.ToInt32(TextBox1.Text);
            Zq58Logical logical = new Zq58Logical();
            ResultInfo<DealRecord> deal= logical.GetDealRecords(num);
            if(deal.ResultNumber==ResultEnum.Success)
            {
                Response.Write(string.Format("<script type='text/javascript'>alert('" + "交易用户卡：{0}，交易卡的信用金额：{1}，交易号：{2}，交易金额：{3}，交易日期：{4},交易类型：{5}，交易终端id：{6}" + "')</script>",
                    deal.Obj.CpuId,deal.Obj.CreditMoney,deal.Obj.DealId,deal.Obj.DealMoney,deal.Obj.DealTime,deal.Obj.DealType,deal.Obj.TerminalId));
            }else
            {
                Response.Write("<script type='text/javascript'>alert('" + deal.Describe + "')</script>");
            }
        }

        protected void Button9_Click(object sender, EventArgs e)
        {
            Zq58Logical zq58Logical=new Zq58Logical();
            BorrowBike bb = new BorrowBike() { OpenAccountDate = "20131010", EndAccountDate = "20201010", BorrowCpuid = "B3719806", BorrowBikePsamid = "201232457685", BorrowBikeid = "B3719806", BorrowTime = "20131118202020" };
            zq58Logical.WriteBorrowBikeInfo(bb);
            ResultInfo<BorrowBike> b1 = zq58Logical.ReadBorrowBikeInfo();
        }

        protected void Button10_Click(object sender, EventArgs e)
        {
            //DbLogical dbLogical=new DbLogical();
            //dbLogical.OpenAccount(new jsh_account() { cpuid = "123123", username = "向钊豫", deposit = 8989.33m, balance = 1238.29m + 100.20m }, 1238.29m, 100.20m, 8989.33m,"xxxx",1,"sdlfk");
        }

        protected void Button11_Click(object sender, EventArgs e)
        {
            //DbLogical dbLogical=new DbLogical();
            //ResultInfo<Dictionary<string, decimal>> result = dbLogical.GetBorrowBikeCost("B3719806", "",
            //                                                                             new DateTime(2013, 11, 18, 20,
            //                                                                                          20, 20));
        }

        protected void Button12_Click(object sender, EventArgs e)
        {
            //DbLogical dbLogical=new DbLogical();
            //dbLogical.RechargeYourPurse(1338.49m, 100m, "B3719806","xx",1,"xx",1);
        }

        protected void Button13_Click(object sender, EventArgs e)
        {
            //DbLogical dbLogical=new DbLogical();
            //dbLogical.UnlockCpuCard(1000.22m, "B3719806", 1, "B3719806", 1, "xx", 1);
        }
    }
}